//
//  TDMineSettingC.m
//  TBRentClient
//
//  Created by tonbright on 2018/6/25.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TDMineSettingC.h"
#import "NetWorkRequest.h"
#import "BaseNavigationController.h"
#import "TBRLoginController.h"
#import "TBRMineModel.h"
#import "TDMineSettingBasicCell.h"
#import "TDTryDriveQuanCell.h"
@interface TDMineSettingC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation TDMineSettingC

-(void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    
    //加载数据
    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    
}

- (IBAction)navBtnClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupUI {
    
    //添加tableView
    [self setupTableView];
}


- (void)setupTableView {
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerNib:[UINib nibWithNibName:@"TDMineSettingBasicCell" bundle:nil] forCellReuseIdentifier:@"TDMineSettingBasicCellId"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TDTryDriveQuanCell" bundle:nil] forCellReuseIdentifier:@"TDTryDriveQuanCellId"];
    self.tableView.showsVerticalScrollIndicator = NO;
}

#pragma mark - 返回组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

#pragma mark - 返回行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

#pragma mark - 返回每行内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        TDTryDriveQuanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TDTryDriveQuanCellId" forIndexPath:indexPath];
        cell.lbe_title.text = @"设置";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    //自定义cell
    TDMineSettingBasicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TDMineSettingBasicCellId" forIndexPath:indexPath];
    [self setupCell:cell indexPath:indexPath];
    return cell;
}

- (NSString *)getIdentifier:(NSIndexPath *)indexPath {
    NSString *iden = @"TDTryDriveQuanCellId";
    if (indexPath.row == 0) {
        iden = @"TDTryDriveQuanCellId";
    }
    else if (indexPath.row == self.dataArray.count - 1) {
        iden = @"TDTryDriveAddQuanCellId";
    }
    else {
        iden = @"TDTryDriveQuanListCellId";
    }
    return iden;
}

- (void)setupCell:(TDMineSettingBasicCell *)cell indexPath:(NSIndexPath *)indexPath {
    TBRMineInfoBasicModel *basicModel = self.dataArray[indexPath.row];
    cell.imv_arrow.hidden = ![basicModel.imageName isEqualToString:@"1"];
    cell.lbe_title.text = basicModel.titleName;
    cell.lbe_detailTitle.text = basicModel.detailName;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    TBRMineInfoBasicModel *basicModel = self.dataArray[indexPath.row];
    if ([basicModel.messageId isEqualToString:@"logooutid"]) {
        //退出登录
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        // app名称
        NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
        __weak typeof(self) weakSelf = self;
        [self showFinishBtnClickAlertShowMessage:[NSString stringWithFormat:@"确定退出%@?",app_Name] block:^{
            if (weakSelf.mineSettingLogooutBlock) {
                weakSelf.mineSettingLogooutBlock();
            }
            [AppSetting shareAppSetting].isLogin = @"0";
            [AppSetting shareAppSetting].userid = @"";
            [AppSetting shareAppSetting].memberid = @"";
            [AppSetting shareAppSetting].tokenuserid = @"";
            [AppSetting shareAppSetting].tokenid = @"";
        }];
    }
}







// MARK: - 加载数据
- (void)loadData {
    [self loadLocalData];
    [self loadNetData];
}
// MARK: - 本地数据
- (void)loadLocalData {
    NSArray *tmpBasicArray = @[@{@"messageId":@"myMessage",
                                 @"imageName":@"",
                                 @"titleName":@"清理缓存",
                                 @"detailName":@"10MB",
                                 @"className":@"TBRNewNoticeListC"},
                               @{@"messageId":@"cleanid",
                                 @"imageName":@"",
                                 @"titleName":@"清理缓存",
                                 @"detailName":@"10MB",
                                 @"className":@"TBRNewNoticeListC"},
                               @{@"messageId":@"lawid",
                                 @"imageName":@"1",
                                 @"titleName":@"法律条款与隐私政策",
                                 @"className":@"TDMineMessageC"},
                               @{@"messageId":@"aboutid",
                                 @"imageName":@"1",
                                 @"titleName":@"关于用车无忧",
                                 @"className":@"TDTryDirveQuanC"},
                               @{@"messageId":@"banbenid",
                                 @"imageName":@"",
                                 @"titleName":@"2.0.0版本",
                                 @"className":@"TBRNewNoticeListC"},
                               @{@"messageId":@"logooutid",
                                 @"imageName":@"",
                                 @"titleName":@"退出",
                                 @"className":@"TBRNewNoticeListC"}
                               ];
    self.dataArray = [NSArray yy_modelArrayWithClass:[TBRMineInfoBasicModel class] json:tmpBasicArray].mutableCopy;
}

// MARK: - 获取网络数据-----
- (void)loadNetData {
   
}
@end
